struct Texture{
    sampler2D map;
};
struct Projector{
    mat4 projectionMatrix;
}

uniform Texture projTex;
uniform Projector projector;

varying vec3 pPosition;
varying vec2 pTexcoord;
varying vec3 pNormal;
varying vec4 pProjectTexcoord;

layout (location = 0) out vec4 fragColor;

vec4 diffuseColor=vec4(0.5,0.2,0.1,1.0);
vec4 specularColor=vec4(1.0,1.0,1.0,1.0);
float shininess=50.0;
vec3 P=pPosition;
vec3 N=normalize(pNormal);
vec3 E=vec3(0.0,0.0,1.0);
vec3 L;
vec3 H;
float NdotE=max(0.0,dot(N,E));
float NdotL;
float NdotH;

void applyLight(){
    vec3 L=normalize(-P);
    vec3 H=normalize(L+E);
	NdotH=max(0.0,dot(N,H));
	NdotL=max(0.0,dot(N,L));
	
	diffuseColor*=NdotL;
	
	float Ispec=pow(NdotH,50.0)*NdotL;
	specularColor*=Ispec;
}

void main(){
	vec4 projectColor=vec4(0.0);
	projectColor=textureProj(projTex.map,pProjectTexcoord);
    applyLight();
	fragColor=diffuseColor+projectColor*0.5;
}
